<?php
/**
 * 添加会员
 * Created by PhpStorm.
 * User: eric
 * Date: 2020/7/22
 * Time: 12:16
 */

namespace App\Admin\Extensions\Tool;

use Encore\Admin\Actions\Action;
use Illuminate\Http\Request;

class UserAdd extends Action
{

    public $name = '添加会员';

    protected $selector = '.new-user';

    public function handle(Request $request)
    {
        //处理逻辑
        $res = app('App\Http\Repositories\Services\UserService')->addUser($request);
        if($res) {
            return $this->response()->success('保存成功')->refresh();
        } else {
            return $this->response()->error('保存失败');
        }
    }

    public function form()
    {
        $this->text('nickname', '会员昵称')->required();
        $this->password('password', '登录密码')->required()->help('6-16位字母数字符号组合')->rules('min:',[
            'regex' => '格式错误',
        ]);
        $this->mobile('mobile', '手机号码')->help('前台登陆账号，手机邮箱任意一项都可以');
        $this->email('email', '邮件地址')->help('前台登陆账号，手机邮箱任意一项都可以');
        $this->text('qq', 'QQ');
        $this->radio('sex', '性别')->options(config('constant.sex'))->default(0);
    }

    public function html()
    {
        return <<<HTML
        <a class="btn btn-sm btn-default new-user" title="添加会员">添加会员</a>
HTML;
    }

}
